package com.tj.jinzao.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.tj.jinzao.R;
import com.tj.jinzao.base.BaseListAdapter;
import com.tj.jinzao.model.Label;

import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;


/**
 * 报告 Adapter
 * Created by wjy on 2019/1/10.
 */
public class LabelListItemAdapter extends BaseListAdapter<Label, LabelListItemAdapter.ViewHolder> {

    public LabelListItemAdapter(Context context, CopyOnWriteArrayList data) {
        super(context, data);
    }
    private ArrayList<String> listLable=new ArrayList<>();
    public ArrayList<String> getListLable(){
        return listLable;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_label_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Label label = mData.get(position);
        holder.name.setText(label.getTagName());
        holder.check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b){
                    listLable.add(label.getTagName());
                }else {
                    listLable.remove(label.getTagName());
                }
            }
        });

    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView name, number;
        CheckBox check;

        public ViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.tv_name);
            number = itemView.findViewById(R.id.tv_number);
            check = itemView.findViewById(R.id.check);
        }
    }


}
